WIT_BASE = wiimms-iso-tools/project

WWT_O = $(WIT_BASE)/cert.o \
  $(WIT_BASE)/dclib-basics.o \
  $(WIT_BASE)/dclib-cli.o \
  $(WIT_BASE)/dclib-color.o \
  $(WIT_BASE)/dclib-debug.o \
  $(WIT_BASE)/dclib-file.o \
  $(WIT_BASE)/dclib-numeric.o \
  $(WIT_BASE)/dclib-option.o \
  $(WIT_BASE)/dclib-parser.o \
  $(WIT_BASE)/dclib-regex.o \
  $(WIT_BASE)/dclib-shift-jis.o \
  $(WIT_BASE)/dclib-tables.o \
  $(WIT_BASE)/dclib-ui.o \
  $(WIT_BASE)/dclib-utf8.o \
  $(WIT_BASE)/dclib-vector.o \
  $(WIT_BASE)/dclib-xdump.o \
  $(WIT_BASE)/file-formats.o \
  $(WIT_BASE)/gen-ui.o \
  $(WIT_BASE)/iso-interface.o \
  $(WIT_BASE)/lib-bzip2.o \
  $(WIT_BASE)/lib-ciso.o \
  $(WIT_BASE)/lib-dol.o \
  $(WIT_BASE)/lib-file.o \
  $(WIT_BASE)/lib-gcz.o \
  $(WIT_BASE)/lib-lzma.o \
  $(WIT_BASE)/lib-sf.o \
  $(WIT_BASE)/lib-std.o \
  $(WIT_BASE)/libwbfs.o \
  $(WIT_BASE)/lib-wdf.o \
  $(WIT_BASE)/lib-wia.o \
  $(WIT_BASE)/match-pattern.o \
  $(WIT_BASE)/patch.o \
  $(WIT_BASE)/rijndael.o \
  $(WIT_BASE)/sha1_one.o \
  $(WIT_BASE)/sha1dgst.o \
  $(WIT_BASE)/titles.o \
  $(WIT_BASE)/tools.o \
  $(WIT_BASE)/wbfs-interface.o \
  $(WIT_BASE)/wiidisc.o \
  $(WIT_BASE)/src/lzma/LzFind.o \
  $(WIT_BASE)/src/lzma/Lzma2Dec.o \
  $(WIT_BASE)/src/lzma/Lzma2Enc.o \
  $(WIT_BASE)/src/lzma/LzmaDec.o \
  $(WIT_BASE)/src/lzma/LzmaEnc.o \
  $(WIT_BASE)/src/libbz2/blocksort.o \
  $(WIT_BASE)/src/libbz2/bzlib.o \
  $(WIT_BASE)/src/libbz2/compress.o \
  $(WIT_BASE)/src/libbz2/crctable.o \
  $(WIT_BASE)/src/libbz2/decompress.o \
  $(WIT_BASE)/src/libbz2/huffman.o \
  $(WIT_BASE)/src/libbz2/randtable.o


ifeq ($(PREFIX),)
	PREFIX := /usr
endif


# Build shared lib from wwt
.PHONY : shared
shared:
	@cd $(WIT_BASE) && CFLAGS="-fPIC -DUSE_SHA_LIB" $(MAKE) wwt
	@mkdir -p bin/shared/
	@gcc -shared $(WWT_O) \
	  -ltinfo -lz -lm -lncurses -lcrypto \
	  -o bin/shared/libwwt.so
	@./gen_config.sh


# Build static lib from wwt
.PHONY : static
static:
	@cd $(WIT_BASE) && $(MAKE) wwt
	@mkdir -p bin/static/
	@ar rcs bin/static/libwwt.a $(WWT_O)


.PHONY : clean
clean:
	@cd $(WIT_BASE) && $(MAKE) clean
	@rm -f bin/static/libwwt.a
	@rm -f bin/shared/libwwt.so


.PHONY : install
install:
	# The lib
	install -d $(DESTDIR)$(PREFIX)/lib/
	install -m 644 bin/shared/libwwt.so $(DESTDIR)$(PREFIX)/lib/
	install -m 644 libwwtConfig.sh $(DESTDIR)$(PREFIX)/lib/

	# Includes
	install -d $(DESTDIR)$(PREFIX)/include/libwwt/dclib
	install -d $(DESTDIR)$(PREFIX)/include/libwwt/libwbfs
	install -d $(DESTDIR)$(PREFIX)/include/libwwt/crypto
	install -m 644 $(WIT_BASE)/dclib/*.h $(DESTDIR)$(PREFIX)/include/libwwt/dclib
	install -m 644 $(WIT_BASE)/version.h $(DESTDIR)$(PREFIX)/include/libwwt
	install -m 644 $(WIT_BASE)/src/*.h $(DESTDIR)$(PREFIX)/include/libwwt
	install -m 644 $(WIT_BASE)/src/libwbfs/*.h $(DESTDIR)$(PREFIX)/include/libwwt/libwbfs
	install -m 644 $(WIT_BASE)/src/crypto/*.h $(DESTDIR)$(PREFIX)/include/libwwt/crypto
